<?php 
class Zend_View_Helper_DisplayListOfMenues extends Zend_View_Helper_Abstract
{
	private $_output = '';
    public function displayListOfMenues($arrayMenues)
    {
		foreach ($arrayMenues as $menu) {
			$this->_output .= '<div id="mod-menu-diario" class="mod-box mod-list mod-list-'. $menu['Color'] .'">';
			$this->_output .= $this->completeMenu($menu);
			$this->_output .= $this->prodInMenu($menu['id'], $menu['Titulo']);
			if (strtolower($menu['Titulo']) === "menu semanal") {
					
				$this->_output .= '<div class="mod-list-extrainfo">
						<p id="menu-weekly-price">$'. $menu['Precio'] .'</p>
						<p>Entrega sin cargo en un radio de 15 cuadras<br><span>Reservas hasta el día sábado</span></p>
						<img alt="" src="/images/site/icn-fridge.png" class="mod-list-icn">
					</div>';
			}
			$this->_output .= '</div>';				
		}
		
		return $this->_output;
    }
	
	protected function completeMenu($dataMenu)
	{
		$outputMenu = '<a href="#"><h2>';
		$time = new Zend_Date();
		switch (strtolower($dataMenu['Titulo'])) {
			case 'menu diario':
				$outputMenu .= $dataMenu['Titulo'] . ' - ' . Nutri_Date_ShowDate::displayDateMenu($time) . '</h2>
					<p>'. $dataMenu['Descripcion'];
				break;
			case 'menu semanal':
				$outputMenu .= $dataMenu['Titulo'] . '</h2>
    				<p>'. $dataMenu['Descripcion'] .'</p>
    				<p><strong>Entrega: </strong><span class="delivery-semanal">'. Nutri_Date_ShowDate::displayDateMenu($dataMenu['Fecha_de_fin']) .'</span>';
				break;	
			default:
				$outputMenu .= $dataMenu['Titulo'] . '</h2>
    				<p>'. $dataMenu['Descripcion'];
				break;
		}
		return $outputMenu .= '</p></a>';				
	}
	
	protected function prodInMenu($idMenu, $nameMenu)
	{	
		$prodInMenu = new Nutri_Model_ProductMenu();
		$resultProductsMenu = $prodInMenu->fetchAll(
			$prodInMenu->select()
						->where('menu_id = ?', $idMenu)
		);
    	
		if(!empty($resultProductsMenu)) {
	    	$productsMenuArray = array();
	    	foreach ($resultProductsMenu as $itemProductMenu) {
	    		$itemProductMenuArray = array();
	    		$itemProductMenuArray['Prod_Titulo'] = $itemProductMenu->getProduct()->getName();
	    		$itemProductMenuArray['Prod_Description'] = $itemProductMenu->getProduct()->getDescription();
				$itemProductMenuArray['Prod_Price'] = $itemProductMenu->getProduct()->getPrice();
	    		
	    		$productsMenuArray[] = $itemProductMenuArray;
	    	}
			
			$output = $this->showMenues($productsMenuArray, $nameMenu);
			return $output;
    	}
		
		
	}
	
	protected function showMenues($obtainProducs, $nameMenu)
	{
		$output = '<ul class="mod-list-menu clearfix">';
		foreach ($obtainProducs as $product) {
			switch (strtolower($nameMenu)) {
			case 'menu diario':
				$output .= '<li class="clearfix">
		            	<p class="mod-list-item">
		               		<span class="mod-list-description">'. $product['Prod_Titulo'] .'</span>
		                	<span class="mod-list-option">'. $product['Prod_Description'] .'</span>
		            	</p>
	            		<p class="mod-list-price">$ <span>'. $product['Prod_Price'] .'</span></p>
        			</li>';
				break;
			case 'menu semanal':
				$output .= '<li class="clearfix">
		            	<p class="mod-list-item">
		               		<span class="mod-list-description">'. $product['Prod_Titulo'] .'</span>
		                	<span class="mod-list-option">'. $product['Prod_Description'] .'</span>
		            	</p>
        			</li>';
				break;	
			default:
				$output .= '<li class="clearfix">
		            	<p class="mod-list-item">
		               		<span class="mod-list-description">'. $product['Prod_Titulo'] .'</span>
		                	<span class="mod-list-option">'. $product['Prod_Description'] .'</span>
		            	</p>
	            		<p class="mod-list-price">$ <span>'. $product['Prod_Price'] .'</span></p>
        			</li>';
				break;
			}
			
		}
		
		return $output .= '</ul>';
	}
}